package net.sx.minemodule.mvp.presenters;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.kedll.library.mvp.BasePresenter;

import net.sx.minemodule.MineApiUtils;
import net.sx.minemodule.mvp.bean.TestIntegralBean;
import net.sx.minemodule.mvp.model.MineIntegralModel;
import net.sx.minemodule.mvp.views.MineIntegralView;

import org.json.JSONObject;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

/**
 * 我的大洋
 * @author 11470
 */
public class MineIntegralPresenter extends BasePresenter<MineIntegralView> {
    private static final String TAG = "MineIntegralPreTag";

    public MineIntegralPresenter(MineIntegralView view) {
        super(view);
    }

    public void addTestData() {

        //在这里创建数据
        addSubscription(Observable.range(0, 5)
                .map(integer -> {
                    TestIntegralBean bean = new TestIntegralBean();
                  bean.setIntegralNum(integer);
                  bean.setMoney(integer);
                    return bean;
                })
                .toList()
                .subscribe(beanList -> mView.addData(beanList)));
    }

    /**
     * 获取积分记录界面我的积分数据
     */
    public void getIntegralData() {
        MineApiUtils.getIntegralData(new Consumer<MineIntegralModel>() {
            @Override
            public void accept(MineIntegralModel jsonObject) throws Exception {
                Log.d(TAG, "accept: jsonObject == " + JSON.toJSONString(jsonObject));
                mView.addMineIntegralData(jsonObject);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                Log.d(TAG, "accept: throwable == " + throwable.toString());
            }
        });
    }

}
